//
//  WQTBListController.swift
//  WQWebData
//
//  Created by huwenqiang on 2019/12/10.
//  Copyright © 2019 huwenqiang. All rights reserved.
//

import UIKit
import HandyJSON

class WQTBListController: UIViewController, UITableViewDelegate, UITableViewDataSource{
    
    
    lazy var mtableView = { () -> UITableView in
        let tableView = UITableView.init()
        tableView.delegate = self
        tableView.dataSource = self
        tableView.register(UITableViewCell.self, forCellReuseIdentifier: "cell")
        return tableView
    }()
    
    var dataArray:[WQTBFavorites] = []
    
    override func viewDidLoad() {
        self.title = "LIST"
        self.view.backgroundColor = .white
        self.view.addSubview(self.mtableView)
        self.mtableView.frame = self.view.frame
        //我的选品库内容列表
        WQRequestHelper.request(param: ["page_no":"1","page_size":"20","fields":"favorites_title,favorites_id,type"], method: .get, apiName: request_api_uatm_favorites, succeed: { (data) in
            let temp = data as! [String:Any]
            let modle = TbkFavorites.deserialize(from: temp, designatedPath: "tbk_uatm_favorites_get_response.results")
            self.dataArray = modle!.tbk_favorites
            self.mtableView.reloadData()
        }){(error) in
            
        }
        
    }
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return self.dataArray.count
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
        cell.textLabel?.text = self.dataArray[indexPath.row].favorites_title
        return cell
    }
    
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        let model = self.dataArray[indexPath.row]
        ViewController.pushToController(nav: self.navigationController ,category: model.favorites_title, favorites_id: model.favorites_id)
    }
}

class TbkFavorites: HandyJSON {
    required init() {}
    var tbk_favorites:[WQTBFavorites] = []
}

class WQTBFavorites: HandyJSON {
    required init() {}
    var favorites_id = ""
    var favorites_title = ""
    var type:Int = 0
    
}
